<template>
  <div class="container">
    <div class="content-wrapper">
      <!-- 图片切换 -->
      <div class="testimonial-pic">
        <div class="avatar-container" v-for="(item, index) in users" :key="index" @click="activeIndex = index">
          <img
            :src="item.img"
            class="user-pic"
            :class="{ 'active-pic': activeIndex === index }"
            :alt="item.name"
          />
          <span class="student-name" :class="{ 'active-name': activeIndex === index }">{{ item.name }}</span>
        </div>
      </div>

      <!-- 文本区域 -->
      <div class="testimonial-text">
        <div
          v-for="(item, index) in users"
          :key="index"
          class="user-text"
          :class="{ 'active-text': activeIndex === index }"
        >
          <!-- 学生信息头部 -->
          <div class="student-info-header">
            <div class="student-avatar-large">
              <img :src="item.img" :alt="item.name"/>
            </div>
            <div class="student-details">
              <h3>{{ item.name }}</h3>
              <div class="overall-progress">
                <p>总体进度</p>
                <el-progress
                  :text-inside="true"
                  :stroke-width="16"
                  :percentage="getOverallProgress(item.process)"
                  :status="getOverallStatus(item.process)"
                />
              </div>
            </div>
          </div>

          <!-- 书籍进度列表 -->
          <div class="books-container">
            <div
              v-for="(book, bookIndex) in item.process || []"
              :key="bookIndex"
              class="book-process-item"
              :class="{ 'completed-book': book.process === 100 }"
            >
              <div class="book-img">
                <img
                  src="@/assets/bookCover.png"
                  alt="教材封面"
                  class="book-cover"
                />
                <div class="book-badge" v-if="book.process === 100">
                  <i class="fas fa-check"></i>
                </div>
              </div>
              <div class="process-div">
                <div class="book-info">
                  <span class="book-name">{{ book.name }}</span>
                  <span class="book-percentage">{{ book.process }}%</span>
                </div>
                <el-progress
                  :text-inside="false"
                  :stroke-width="6"
                  :percentage="book.process"
                  :status="book.process === 100 ? 'success' : (book.process > 60 ? 'warning' : 'info')"
                />
              </div>
            </div>

            <!-- 没有数据时显示 -->
            <div class="no-data" v-if="!(item.process && item.process.length)">
              <i class="fas fa-book-open"></i>
              <p>暂无学习进度数据</p>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'StudentProcess',
  data() {
    return {
      activeIndex: 0,
      users: [
        {
          name: '章北海',
          process: [
            { name: '人教版一年级上册', process: 80 },
            { name: '人教版二年级上册', process: 96 },
            { name: '人教版三年级上册', process: 45 },
            { name: '人教版四年级上册', process: 65 },
            { name: '人教版五年级上册', process: 24 },
            { name: '人教版六年级上册', process: 67 },
            { name: '人教版七年级上册', process: 89 }
          ],
          img: require('@/views/course/StudentProgress/assets/章北海.webp')
        },
        {
          name: '罗辑',
          process: [
            { name: '人教版一年级上册', process: 100 },
            { name: '人教版二年级上册', process: 100 },
            { name: '人教版三年级上册', process: 78 },
            { name: '人教版四年级上册', process: 32 }
          ],
          img: require('@/views/course/StudentProgress/assets/罗辑.webp')
        },
        {
          name: '史强',
          process: [
            { name: '人教版一年级上册', process: 45 },
            { name: '人教版二年级上册', process: 30 },
            { name: '人教版三年级上册', process: 15 }
          ],
          img: require('@/views/course/StudentProgress/assets/史强.webp')
        },
        {
          name: '褚岩',
          process: [
            { name: '人教版四年级上册', process: 90 },
            { name: '人教版五年级上册', process: 85 },
            { name: '人教版六年级上册', process: 100 },
            { name: '人教版七年级上册', process: 76 }
          ],
          img: require('@/views/course/StudentProgress/assets/储岩.webp')
        },
        {
          name: '东方延续',
          process: [],
          img: require('@/views/course/StudentProgress/assets/东方.webp')
        }
      ]
    }
  },
  methods: {
    // 计算总体进度
    getOverallProgress(processList) {
      if (!processList || !processList.length) return 0
      const total = processList.reduce((sum, item) => sum + item.process, 0)
      return Math.round(total / processList.length)
    },
    // 获取总体进度状态
    getOverallStatus(processList) {
      const progress = this.getOverallProgress(processList)
      if (progress === 100) return 'success'
      if (progress > 60) return 'warning'
      return 'info'
    }
  }
}
</script>

<style scoped>
.container {
  width: 100%;
  height: 100%;
  background-color: #f5f7fa;
  box-sizing: border-box;
}

.content-wrapper {
  height: 100%;
  display: flex;
  gap: 2rem;
  margin: 0 auto;
  background-color: #ffffff;
  border-radius: 20px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.08);
  overflow: hidden;
}

/* 头像列表样式 */
.testimonial-pic {
  width: 180px;
  background-color: #f8f9fa;
  padding: 1.5rem 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  border-right: 1px solid #f1f1f1;
  overflow-y: auto;
}

.avatar-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-bottom: 1rem;
  cursor: pointer;
  transition: all 0.3s ease;
  padding: 0.5rem;
  border-radius: 12px;
  width: 100%;
}

.avatar-container:hover {
  background-color: rgba(52, 152, 219, 0.05);
}

.user-pic {
  width: 70px;
  height: 70px;
  border-radius: 50%;
  object-fit: cover;
  border: 3px solid transparent;
  transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}

.user-pic.active-pic {
  width: 85px;
  height: 85px;
  border-color: #3498db;
  box-shadow: 0 6px 12px rgba(52, 152, 219, 0.2);
}

.student-name {
  margin-top: 0.5rem;
  font-size: 0.9rem;
  color: #7f8c8d;
  font-weight: 500;
  transition: all 0.3s ease;
}

.student-name.active-name {
  color: #3498db;
  font-weight: 600;
}

/* 文本内容区域 */
.testimonial-text {
  flex: 1;
  padding: 2rem;
  min-height: 600px;
  position: relative;
}

.user-text {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  padding: 2rem;
  box-sizing: border-box;
  opacity: 0;
  visibility: hidden;
  transform: translateX(20px);
  transition: all 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.user-text.active-text {
  opacity: 1;
  visibility: visible;
  transform: translateX(0);
}

/* 学生信息头部 */
.student-info-header {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  margin-bottom: 2rem;
  padding-bottom: 1.5rem;
  border-bottom: 1px solid #f1f1f1;
}

.student-avatar-large {
  width: 100px;
  height: 100px;
  border-radius: 50%;
  overflow: hidden;
  box-shadow: 0 6px 15px rgba(0, 0, 0, 0.1);
}

.student-avatar-large img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.student-details h3 {
  font-size: 1.5rem;
  margin-bottom: 1rem;
  color: #2c3e50;
}

.overall-progress {
  width: 300px;
}

.overall-progress p {
  margin-bottom: 0.5rem;
  font-size: 0.9rem;
  color: #7f8c8d;
  display: flex;
  justify-content: space-between;
}

/* 书籍进度列表 */
.books-container {
  height: calc(100vh - 22rem);
  overflow-y: auto;
  padding-right: 1rem;
}

.books-container::-webkit-scrollbar {
  width: 6px;
}

.books-container::-webkit-scrollbar-track {
  background: #f1f1f1;
  border-radius: 10px;
}

.books-container::-webkit-scrollbar-thumb {
  background: #ddd;
  border-radius: 10px;
}

.books-container::-webkit-scrollbar-thumb:hover {
  background: #bbb;
}

.testimonial-pic::-webkit-scrollbar {
  width: 6px;
}

.testimonial-pic::-webkit-scrollbar-track {
  background: #f1f1f1;
  border-radius: 10px;
}

.testimonial-pic::-webkit-scrollbar-thumb {
  background: #ddd;
  border-radius: 10px;
}

.testimonial-pic::-webkit-scrollbar-thumb:hover {
  background: #bbb;
}

.book-process-item {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  padding: 1rem 1.2rem;
  background-color: #f8f9fa;
  border-radius: 12px;
  margin-bottom: 1rem;
  transition: all 0.3s ease;
  border-left: 4px solid transparent;
}

.book-process-item:hover {
  transform: translateY(-2px);
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.05);
}

.book-process-item.completed-book {
  border-left-color: #2ecc71;
  background-color: rgba(46, 204, 113, 0.05);
}

.book-img {
  width: 80px;
  position: relative;
}

.book-cover {
  width: 100%;
  height: 110px;
  object-fit: cover;
  border-radius: 6px;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.1);
}

.book-badge {
  position: absolute;
  top: -8px;
  right: -8px;
  width: 30px;
  height: 30px;
  background-color: #2ecc71;
  color: white;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
}

.process-div {
  flex: 1;
}

.book-info {
  display: flex;
  justify-content: space-between;
  margin-bottom: 0.5rem;
  align-items: center;
}

.book-name {
  font-weight: 500;
  color: #2c3e50;
}

.book-percentage {
  font-size: 0.9rem;
  font-weight: 600;
}

/* 无数据状态 */
.no-data {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 3rem 0;
  color: #95a5a6;
  text-align: center;
}

.no-data i {
  font-size: 3rem;
  margin-bottom: 1rem;
  opacity: 0.5;
}

/* 响应式设计 */
@media (max-width: 768px) {
  .content-wrapper {
    flex-direction: column;
  }

  .testimonial-pic {
    width: 100%;
    flex-direction: row;
    padding: 1rem;
    overflow-x: auto;
    border-right: none;
    border-bottom: 1px solid #f1f1f1;
  }

  .avatar-container {
    margin-bottom: 0;
    margin-right: 1rem;
    flex-shrink: 0;
  }

  .student-info-header {
    flex-direction: column;
    text-align: center;
  }

  .overall-progress {
    width: 100%;
  }

  .testimonial-text {
    padding: 1rem;
  }

  .user-text {
    padding: 1rem 0;
  }
}
</style>
